package
{
	import UIUtils.uif_util;
	
	import cardsbody.pi_multicard;
	
	import com.adobe.serialization.json.JSON;
	
	import flash.display.Sprite;
	
	import templates.pi_templates1;

	[SWF(width="1060", height="880", backgroundColor="#FFFFFF")]
	public class pj_dataReset extends Sprite {
//		private var noIDs: Array = [12452,12451,12450,12238,12425,12304,12241,12210,12193,12192,12191,12190,12189,12188,12171,12170,12169,12164,12163,12143,12142,12028,11957,11823,11801,11800,11785,11784,11679,11629,11600,11431,11430,11429,11428,11325,11323,11289,11288,11037,11019,10939,10936,10879,10877,10876,10793,10751,10750,10729,10728,10727,10707,10706,10657,10613,10612,10521,10506,10504,10475,10474,10472,10470,10469,10403,10187,10183,10114,10055,10053,9957,9863,9794,9793,9792,9789,9732,9731,9672,9620,9614,9615,7092,7072,7071,7005,7004,7003,6993,6992,6991,6990,6989,6988,6987,6959,6857,6636,6635,6605,6604,6603,6597,6594,6590,6589,6588,6586,6585,6584,6582,6581,6580,6576,6563,6559,6558,6557,6556,6555,6533,6530,6528,6527,6490,6489,6488,6487,6486,6485,6484,6472,6355,6352,6129,4971,4749,4485,12397,12396,12183,12182,12181,12176,12141,12125,12071,12037,11971,11869,11868,11867,11866,11850,11849,11815,11812,11804,11770,11766,11762,11621,11245,10910,10871,10821,10820,10608,10555,10554,10549,10510,10509,10508,10507,10492,10222,10206,10204,10199,9911,9909,9803,9726,9725,9719,7113,7112,6933,6836,6804,6708,6518,6516,6515,4577,4538,11496,11464,11463,11462,11450,11449,11448,11447,11446,11445,11442,11441,11439,11412,11408,11407,11399,11393,11392,11391,11341,11340,11279,11270,11260,11259,11115,11073,11072,11039,11038,10954,10795,7106,7105,7104,7037,7036,6816,6685,6684,6496,6495,6494,4456,12313,12312,12311,12310,12309,12308,12307,12254,12246,12245,12244,12243,12242,12222,12210,12111,12071,12047,12013,11879,11878,11877,11876,11875,11874,11873,11872,11871,11870,11850,11804,11484,11391,11340,11270,11037,10918,10753,10752,10521,10403,10156,9651,7103,7063,7064,7062,7061,7060,7036,7020,7005,7004,7003,6931,6930,6929,6928,6927,6926,6925,6924,6923,6922,6921,6830,6829,6779,6636,6635,6614,6613,6612,6544,6543];
//Дни рождения		private var noIDs: Array = [7358,7357,7259,7092,6988,6594,6597,6635,6636,6480,6162,6161,4856,5017,4665,4662,4516,4500,4485,4426,2021,1479,1125,938];
//Детские		private var noIDs: Array = [12605,12603,12598,12597,12596,12594,12592,12513,12458,12457,12456,12313,12312,12311,12310,12309,12308,12307,12284,12283,12282,12281,12280,12279,12246,12245,12244,12243,12242,12221,12201,12200,12199,12198,12197,12196,12195,12194,12117,12116,12115,12111,12012,12011,12010,12009,12008,12007,12006,12005,12004,12003,12002,11970,11969,11968,11967,11966,11965,11964,11963,11962,11961,11960,11959,11958,11934,11933,11932,11931,11930,11929,11928,11927,11926,11925,11907,11906,11905,11904,11903,11902,11901,11900,11899,11898,11879,11878,11877,11876,11875,11874,11873,11872,11871,11870,11830,11829,11828,11827,11826,11825,11481,11294,11293,11292,11291,11290,11078,11057,11056,11055,11048,11047,11046,11045,11044,11042,10996,10920,10918,10902,10855,10837,10836,10835,10834,10833,10773,10772,10684,10683,10362,10361,10360,10359,10358,10357,10315,10313,10311,10255,10156,10128,10125,10033,10032,9923,9921,9920,9841,9840,9839,9838,9837,9836,9835,9834,9833,9832,9831,9830,9829,9828,9827,9826,9825,9824,9823,9822,9821,9820,9819,9818,9817,9816,9815,9814,9813,9812,9768,9767,9765,9710,9678,9676,9651,9566,9629,9628,9627,9626,9625,9624,9623,9622,9621,9544,24,84];
//Приколы		private var noIDs: Array = [12491,12124,12123,12122,12121,12025,12024,12023,12022,12021,12020,12019,12018,12017,12016,12015,12013,11945,11944,11943,11942,11941,11939,11938,11935,11914,11913,11912,11911,11910,11909,11908,11332,11005,10978,10754,10753,10752,10691,10690,10625,10566,10565,10564,10563,10562,10561,10420,10419,10418,10417,10416,10316,9996,9903,9902,9900,9899,9655,9654];
//arhive2		private var noIDs: Array = [8745,8744,8743,8742,8741,8740,8678,8677,8675,8673,8642,8641,8639,8638,8621,8620,8603,8602,8589,8588,8584,8583,8572,8538,8529,8491,8490,8489,8467,8430,8415,8414,8413,8412,8411,8410,8409,8393,8392,8386,8378,8377,8375,8374,8373,8372,8371,8356,8315,8313,8312,8311,8307,8306,8305,8291,8290,8269,8235,8228,8227,8209,8188,8187,8185,8184,8183,8182,8181,8180,8179,8178,8177,8176,8226,8225,8224,8223,8222,8221,8220,8219,8218,8217,8216,8215,8214,8213,8212,8211,8210,8209,8164,8162,8161,8158,8157,8156,8155,8154,8153,8152,8151,8150,8149,8148,8134,8131,8123,8120,8119,8113,8112,8064,8061,8060,8039,8046,8045,8044,8025,8021,7985,7939,7907,7886,7885,7884,7883,7882,7881,7880,7879,7878,7864,7863,7862,7861,7860,7777,7776,7775,7774,7773,7772,7771,7770,7769,7768,7767,7758,7743,7733,7725,7724,7723,7722,7721,7720,7719,7713,7710,7709,7708,7707,7706,7705,7704,7703,7702,7701,7700,7699,7698,7697,7696,7693,7692,7691,7670,7669,7638,7633,7624,7623,7608,7591,7590,7578,7572,7571,7570,7569,7568,7567,7566,7565,7564,7563,7562,7560,7559,7558,7557,7556,7555,7554,7553,7539,7519,7518,7517,7507,7499,7498,7495,7489,7487,7481,7479,7476,7475,7474,7458,7403,7402.7398,7397,7396,7388,7387,7386,7366,7365,7364,7360,7358,7354,7340,7337,7336,7335,7334,7323,7324,7322,7321,7319,7318,7317,7300,7270,7269,7266,7265,7264,7259,7242,7239,7237,7236,7231,7227,7219,7218,7217,7216,7215,7214,7210,7209,7207,7206,7188,7162,7161,7160,7159,7151,7150,7149,5068,5063,5060,5059,5058,5057,5039,5038,5019,5017,4431,4426,4423,4421,4420,4416,4415,4414,4395,4391,4389,4388,4387,4383,4382,4364,4359,4356,4355,4354,4353,4294,4288,4260,4254,4244,4240,4237,4213,4205,4204,4201,4171,4170,4168,4166,4165,4164,4161,4160,4158,4156,4154,4153,4150,4149,4147,4146,4145,4144,4143,4142,4141,4140,4139,4136,4135,4134,4133,4132,4131,4130,4129,4128,4127,4126,4125,4124,4123,4122,4121,4120,4119,4118,4117,4116,4115,4114,4113,4112,4111,4110,4109,4108,4107,4106,4105,4104,4103,4102,4101,4100,4099,4098,4097,4057,4003,2160,2145,2119,2109,2103,2098,2091,2083,2082,2078,2077,2076,2075,2074,2069,2068,2067,2066,2056,2054,2050,2048,2047,2046,2041,2037,2027,2026,2021,2020,2015,2007,2006,2005,2004,2004,2002,2001,1999,1955,1954,1953,1951,1948,1947,1942,1941,1939,1938,1917,1894,1874,1867,1856,1843,1842,1841,1831,1830,1829,1790,1733,1732,1722];
		private var noIDs: Array = [1699,1695,1693,1692,1680,1650,1646,1634,1633,1632,1596,1595,1594,1593,1592,1591,1690,1589,1588,1587,1586,1585,1573,1564,1563,1561,1559,1554,1553,1548,1547,1542,1541,1524,1523,1522,1521,1520,1519,1479,1474,1473,1472,1471,1470,1469,1468,1467,1466,1465,1463,1461,1454,1451,1450,1450,1448,1447,1442,1431,1424,1425,1413,1410,1408,1364,1490,1491,1492,1629,1628,1351,1305,1299,1298,1297,1296,1280,1270,1265,1259,1195,1185,1169,1168,1167,1166,1165,1157,1156,1155,1154,1153,1121,1117,1116,1095,1072,1071,1068,1066,1053,1034,1027,993,967,933,922,917,906,813,812,808,807,801,800,799,798,766,765,764,519,430,711,710,709,708,707,706,705,702,651,650,649,648,647,652,589,556,537,536,535,534,533,518,504,505,503,502,548,424,423,422,421,604,420,419,602,418,398,346,344,321,318,297,296,178,173,163,154,135,132,110,109,208,100,93,197,90,205,207];		
		private var groups: Array = [2];
		private var startID: uint = 1;
		
		private var fields: Array = [];
		
		public static function resetData(infoList: Array, setGroupID: int=0): Array {
			var i: int;
			
			function createElement(source: Object, index: int, num: int): Object {
				var setObj: Object = new Object();
				for (var i: String in source) {
					if (i != 'id') {
						if (source[i] is Array) {
							if (source[i][num] != undefined) setObj[i] = source[i][num];
						} else setObj[i] = source[i];
					} else setObj.id = index;
				}
				if (setGroupID) setObj.group =  setGroupID;
				return setObj;
			}
			
			for (i = 0; i<infoList.length; i++) {
				var obj: Object = infoList[i];
				if (obj && (obj.id is Array)) {
					infoList.splice(i, 1);
					i--;
					var num	: int = 0;
					var n	: int;
					if (obj.id.length == 2) {
						for (n = obj.id[0]; n <= obj.id[1]; n++) {
							infoList.push(createElement(obj, n, num));
							num++;
						}
					} else {
						for (n = 0; n <= obj.id.length; n++) {
							infoList.push(createElement(obj, obj.id[n], num));
							num++;
						}
					}
				} else if (setGroupID) obj.group =  setGroupID;
			}
			
			
/*			for (i = 0; i<infoList.length; i++) {
				var obj: Object = infoList[i];
				obj.group = (obj.group>=100)?(obj.group-100):obj.group;
				if (obj.id is Array) {
					var index: int = obj.id[1] - obj.id[0];
					for (var n: int = obj.id[1]; n > obj.id[0]; n--) {
						var copy: Object = uif_draw.union({}, obj);
						copy.id = n;
						if (obj.spots) copy.spots = obj.spots[index]; 
						infoList.push(copy);
						index--;
					}
					obj.id = obj.id[0];
					if (obj.spots) obj.spots = obj.spots[0]; 
				}
			}*/
			
			infoList.sortOn('id', Array.NUMERIC);
			return infoList;
		}
		
		public function union(list1: Array, list2: Array): Array {
			var result: Array = new Array();
			for (var i:int=0; i<list1.length; i++) {
				var item: Object = null;
				for (var n:int=0; n<list2.length; n++) {
					if (list2[n].id == list1[i].id) {
						item = uif_util.union(list1[i], list2[n]);
						break;
					}
				}
				if (item) result.push(item);
				else result.push(list1[i]);
			}
			return result;
		}
		
		public function pj_dataReset() {
			super();
			
//			pi_data.maskInfoList = pi_data.maskInfoList.concat(pi_templates1.maskInfoList);
			pi_data.resetData(pi_data.maskInfoList);
			var mdata	: Array = pi_data.maskInfoList; 
//			var mdata	: Array = resetData((new group_arhive()).data);
//			var mdata	: Array = resetData((new group_arhive2()).data);
			
//			var gd: group_birthday = new group_birthday();
//			var mdata	: Array = resetData(gd.data, 16);
//			mdata = union(resetData((new group_arhive()).data), mdata);
//			mdata = union(resetData((new group_arhive2()).data), mdata);
			
//			mdata = union(resetData((new group_arhive3()).data), mdata);
			var i		: int;
			var ldata	: Array = new Array();
			
/*			for (var i: int=0; i<pi_data.cardGroup.length; i++) {
				if (pi_data.cardGroup[i].hasOwnProperty('group'))
					groups.push(pi_data.cardGroup[i].group);
			}*/
			
			i = 0;
			trace('[');
			while (i < mdata.length) {
				if (mdata[i].id >= startID) {
//					if ((noIDs.indexOf(mdata[i].id) == -1)
						//&& (groups.indexOf(mdata[i].group) > -1) ) 
						if (mdata[i].maskClass == pi_multicard) {
//						trace(JSON.encode(mdata[i]) + ',');
							trace('{id=' + mdata[i].id + ', group:' + mdata[i].group + '},');
						}
				}
				i++;
			}
			trace(']');
		}
	}
}